package com.esender.api.filter;

import com.esender.common.model.StandardSubmit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RefreshScope
public class CheckFilterContext {
    @Autowired
    private Map<String,CheckFilter> checkFilters;

    // 从nacos获取动态filter顺序表示尝试从属性文件中获取名为filters的属性。如果找不到filters属性，则会使用后面的逗号分隔的默认值列表：apiKey,mobile,template,sign,ip,fee
    @Value("${filters:apiKey,mobile,template,sign,ip,fee}")
    private String filters;

    public void check(StandardSubmit standardSubmit){
        String[] filterArray = filters.split(",");
        for (String filter:filterArray) {
            CheckFilter checkFilter = checkFilters.get(filter);
            checkFilter.check(standardSubmit);
        }
    }
}
